package org.example.wx.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.common.utils.ResponseUtil;
import org.example.db.entity.CategoryFirst;
import org.example.db.entity.CategorySecond;
import org.example.wx.service.WxCategoryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@Api(tags = "微信商品分类页面")
@RequestMapping("/wx/category")
public class WxCategoryController {

    WxCategoryService wxCategoryService;

    public WxCategoryController(WxCategoryService wxCategoryService) {
        this.wxCategoryService = wxCategoryService;
    }

    /**
     *
     * @param categoryId secondary category id
     * @return parentCategory, currentCategory, brotherCategoryList
     */
    @GetMapping("/index")
    @ApiOperation("微信商品分类页面的主要信息")
    public Object index(@RequestParam Long categoryId){


        CategoryFirst parentCategory = wxCategoryService.getParentCategoryBySecondaryId(categoryId);
        CategorySecond currentCategory = wxCategoryService.getCategorySecond(categoryId);
        List<CategorySecond> brotherCategoryList = wxCategoryService.getCategorySecondListParentId(parentCategory.getId());
        HashMap<String, Object> map = new HashMap<>();
        map.put("parentCategory", parentCategory);
        map.put("currentCategory", currentCategory);
        map.put("brotherCategoryList", brotherCategoryList);
        return ResponseUtil.ok(map);
    }
}
